<?php
/**
 * 文件描述
 * =================================================================
 * 文件名称  DataBase.class
 * -----------------------------------------------------------------
 * 作    者  xiaokai<601200376@qq.com>
 * -----------------------------------------------------------------
 * 创建时间  2010-1-19
 * -----------------------------------------------------------------
 * 版权信息  创思工作室
 * =================================================================
 */

abstract class DataBase
{
   protected $_conn         = null;

   protected $_result       = null;

   protected $_errStr       = '';

   protected $_sqlStr       = '';

   protected $_queryCount   = 0;

   protected $_fetchFunc    = 'assoc';

   protected $_table        = '';

   abstract public function connect($host, $user, $password, $name, $pconnect, $table, $return);

   abstract public function selectDataBase($database);

   abstract public function query();

   abstract public function execute();

   abstract function insert($data);

   abstract function update($data, $where);

   abstract function delete($where);

   abstract public function insertId();

   abstract public function affectedRows();

   abstract public function free();

   abstract public function close();

   abstract public function error();

   abstract public function findAll($args, $all = true);

   public function find($args)
   {
       return $this->findAll($args, false);
   }

   /**
    * 格式化SQL命令
    *
    * @access   public
    * @param    string
    * @return   void
    */
   protected function formatSqlStr($args)
   {
       $this->_sqlStr = array_shift($args);
       $this->_sqlStr = strtr($this->_sqlStr, array('?' => '\'%s\'', '__TABLE__' => $this->_table));
       $this->_sqlStr = vsprintf($this->_sqlStr, array_map('mysql_real_escape_string', $args));
   }

   /**
    * 提示错误
    * @access	protected
    * @param	string  $message    错误信息
    * @return	bool    $sql        是否显示SQL命令
    */
   protected function halt($message = '', $sql = true)
   {
       $message  = !empty($message) ? $message : $this->error();
       $message .= '<br />';
       $message .= $sql ? $this->_sqlStr : '';
       sysError($message);
   }
}